<script lang="ts" setup>
import { logout } from "/stores/user";
import { logout as logoutApi } from '/api/provide';

async function onLogout() {
	const { confirm } = await uni.showModal({
		title: '提示',
		content: '确定要退出登录吗？',
	})
	if (!confirm) return
	uni.showLoading()
	await logoutApi()
	await logout()
	uni.showToast({
		title: '退出登录成功',
		icon: 'none',
	})
}
</script>

<template>
	<view class="T_page">
		<view class="list">
			<view @click="uni.navigateTo({ url: '/pages/editPassword/index' })">
				<image class="icon" src="/static/svg/lock.svg" />
				<text>修改密码</text>
				<uni-icons type="right" :size="uni.$rpxToPx(30)" color="#D1D5DB" />
			</view>
		</view>
		<button class="btn" type="warn" @click="onLogout">退出登录</button>
	</view>
</template>

<style lang="scss" scoped>
.T_page {
	display: flex;
	flex-direction: column;

	>.list {
		background-color: #fff;
		border-radius: 20rpx;
		margin-top: 30rpx;
		padding: 0 20rpx;

		>view {
			height: 110rpx;
			display: flex;
			align-items: center;
			gap: 20rpx;

			&+view {
				border-top: 1rpx solid #f8f8f8;
			}

			>.icon {
				width: 30rpx;
				height: 30rpx;
				margin-left: 10rpx;
			}

			>text {
				flex-grow: 1;
				font-size: 28rpx;
				color: #374151;
			}
		}
	}

	>.btn {
		margin: auto 0 40rpx;
	}
}
</style>
